package net.valerijtimakov.homefinances.dao.storages.common.mysql.query_builders;

import net.valerijtimakov.homefinances.exceptions.AppExceptionWrongState;

public class DeleteQuery extends ConditionedQuery {
	
	public DeleteQuery() {
		super();
	}

	public DeleteQuery(String tableName) {
		super(tableName);
	}
	
	@Override
	public String getSql() throws AppExceptionWrongState {
		StringBuilder whereLine = where.getWhereConditionLine();
		if (whereLine.length() == 0) {
			throw new AppExceptionWrongState("Удаление всех экземпляров недопустимо!");
		}
		return "DELETE FROM `" + tableName + "`" + whereLine + ";";
	}
}
